package CyclicLinkedList;

public class Test {
        public static void main(String[] args) {
            // 测试单向循环链表
            System.out.println("---测试单向循环链表---");
            SinglyCircularLinkedList scll = new SinglyCircularLinkedList();

            System.out.println("---初始化链表---");
            System.out.println("head= " + scll);

            System.out.println("---增加结点(头插法)---");
            scll.insertAtHead(13);
            scll.insertAtHead(14);
            scll.insertAtHead(15);
            scll.display();
            System.out.println("length: " + scll.getLength());

            System.out.println("---增加结点(尾插法)---");
            scll.insertAtTail(21);
            scll.insertAtTail(22);
            scll.insertAtTail(23);
            scll.display();
            System.out.println("length: " + scll.getLength());

            System.out.println("---删除结点---");
            System.out.println("删除数据为5120的结点");
            System.out.println("删除前：");
            scll.display();
            boolean result = scll.deleteNode(5120);
            System.out.println("---删除" + (result ? "成功" : "失败"));
            scll.display();
            System.out.println("length: " + scll.getLength());

            System.out.println("删除数据为13的结点");
            System.out.println("删除前：");
            scll.display();
            result = scll.deleteNode(13);
            System.out.println("---删除" + (result ? "成功" : "失败"));
            scll.display();
            System.out.println("length: " + scll.getLength());

            System.out.println("---反转链表---");
            System.out.println("反转前：");
            scll.display();
            scll.reverse();
            System.out.println("反转后：");
            scll.display();

            // 测试双向循环链表
            System.out.println("\n---测试双向循环链表---");
            DoublyCircularLinkedList dcll = new DoublyCircularLinkedList();

            System.out.println("---初始化链表---");
            System.out.println("head= " + dcll);

            System.out.println("---增加结点(头插法)---");
            dcll.insertAtHead(13);
            dcll.insertAtHead(14);
            dcll.insertAtHead(15);
            dcll.display();
            System.out.println("length: " + dcll.getLength());

            System.out.println("---增加结点(尾插法)---");
            dcll.insertAtTail(21);
            dcll.insertAtTail(22);
            dcll.insertAtTail(23);
            dcll.display();
            System.out.println("length: " + dcll.getLength());

            System.out.println("---反转链表---");
            System.out.println("反转前：");
            dcll.display();
            dcll.reverse();
            System.out.println("反转后：");
            dcll.display();
        }
    }